﻿Imports System.Windows.Forms

Public Class NewProjectDialog

    Public FileName As String = ""

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        Dim code As String = ""
        Select Case ComboBox1.SelectedItem
            Case "VisualBasic"
                code = My.Resources.vbtemplate
            Case "CSharp"
                code = My.Resources.cstemplate
        End Select

        Dim Script = <?xml version="1.0" encoding="utf-8"?>
                     <Script>
                         <References>
                             <Reference>System.dll</Reference>
                         </References>
                         <Code Language=<%= ComboBox1.Text %>>
                             <%= code %>
                         </Code>
                     </Script>

        Try
            Dim sw As New IO.StreamWriter(TextBox1.Text)
            sw.Write(Script.ToString)
            sw.Close()
        Catch ex As Exception

        End Try

        FileName = TextBox1.Text
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Save As New SaveFileDialog
        Save.Filter = "OnFly Calculator Script (*.ofcs)|*.ofcs"
        Save.AddExtension = True
        If Save.ShowDialog = Forms.DialogResult.OK Then
            TextBox1.Text = Save.FileName

        End If
    End Sub
End Class
